import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int[] arr=new int[5];
        for(int i=0;i<5;i++){
            arr[i]=sc.nextInt();
        }
        int count=0;
        for(int i=0;i<5;i++){
            if(findNum(arr[i])){
                count++;
            }
        }
        System.out.println(count);
    }
    public static boolean findNum(int num){
        String str=String.valueOf(num);
        int g=str.charAt(3)-'0';
        int s=str.charAt(2)-'0';
        int b=str.charAt(1)-'0';
        int q=str.charAt(0)-'0';
        if(q==s&&g-1==b){
            return true;
        }
        return false;
    }
}